/* $Id: serialize.h 15 2006-12-15 23:14:45Z judas $ */

#ifndef NIH_MARSHALL_H
#define NIH_MARSHALL_H 1

#include <nih/cdefs.h>

BEGIN_C_DECLS

#include <inttypes.h>
#include <sys/types.h>

/* Serialize */

extern ssize_t nih_s_int8(void *buf, size_t buflen, int8_t int8);
extern ssize_t nih_s_uint8(void *buf, size_t buflen, uint8_t uint8);

extern ssize_t nih_s_int16(void *buf, size_t buflen, int16_t int16);
extern ssize_t nih_s_uint16(void *buf, size_t buflen, uint16_t uint16);

extern ssize_t nih_s_int32(void *buf, size_t buflen, int32_t int32);
extern ssize_t nih_s_uint32(void *buf, size_t buflen, uint32_t uint32);

extern ssize_t nih_s_int64(void *buf, size_t buflen, int64_t int64);
extern ssize_t nih_s_uint64(void *buf, size_t buflen, uint64_t uint64);

extern ssize_t nih_s_float(void *buf, size_t buflen, float floa);
extern ssize_t nih_s_double(void *buf, size_t buflen, double doubl);
#if HAVE_LONG_DOUBLE
extern ssize_t nih_s_ldouble(void *buf, size_t buflen, long double ldoubl);
#else /* HAVE_LONG_DOUBLE */
#define nih_s_ldouble(buf, buflen, ldoubl) \
        nih_s_double((buf), (buflen), (double) (ldoubl)
#endif /* HAVE_LONG_DOUBLE */


extern ssize_t nih_s_str(void *buf, size_t buflen, const char *str);
extern ssize_t nih_s_bin(void *buf, size_t buflen,
                         const void *bin, size_t binlen);

/* Deserialize */

extern ssize_t nih_d_int8(int8_t *int8, const void *buf, size_t buflen);
extern ssize_t nih_d_uint8(uint8_t *uint8, const void *buf, size_t buflen);

extern ssize_t nih_d_int16(int16_t *int16, const void *buf, size_t buflen);
extern ssize_t nih_d_uint16(uint16_t *uint16, const void *buf, size_t buflen);

extern ssize_t nih_d_int32(int32_t *int32, const void *buf, size_t buflen);
extern ssize_t nih_d_uint32(uint32_t *uint32, const void *buf, size_t buflen);

extern ssize_t nih_d_int64(int64_t *int64, const void *buf, size_t buflen);
extern ssize_t nih_d_uint64(uint64_t *uint64, const void *buf, size_t buflen);

extern ssize_t nih_d_float(float *floa, const void *buf, size_t buflen);
extern ssize_t nih_d_double(double *doubl, const void *buf, size_t buflen);
#if HAVE_LONG_DOUBLE
extern ssize_t nih_d_ldouble(long double *ldoubl,
                             const void *buf, size_t buflen);
#else /* HAVE_LONG_DOUBLE */
#define nih_d_ldouble(ldoubl, buf, buflen) \
        nih_d_double((double) (ldoubl), (buf), (buflen))
#endif /* HAVE_LONG_DOUBLE */

extern ssize_t nih_d_str(char *str, size_t strlen,
                         const void *buf, size_t buflen);
extern ssize_t nih_d_bin(void *bin, size_t binlen,
                         const void *buf, size_t buflen);

END_C_DECLS

#endif /* NIH_MARSHALL_H */

